package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingGradeDto;
import com.zzyl.entity.NursingGrade;
import com.zzyl.mapper.NursingGradeMapper;
import com.zzyl.service.NursingGradeService;
import com.zzyl.vo.NursingGradeVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class NursingGradeServiceImpl implements NursingGradeService {

    @Autowired
    NursingGradeMapper nursingGradeMapper;
    @Override
    public List<NursingGradeVo> listAll() {
        List<NursingGradeVo> nursingGrades = nursingGradeMapper.listAll();
        return nursingGrades;
    }

    @Override
    public void insert(NursingGradeDto nursingGradeDto) {
        NursingGrade nursingGrade = BeanUtil.toBean(nursingGradeDto, NursingGrade.class);
        nursingGradeMapper.insert(nursingGrade);
    }

    @Override
    public PageResponse<NursingGradeVo> findByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingGradeVo> page=nursingGradeMapper.getPageList(name,status);
        PageResponse<NursingGradeVo> nursingGradeVoPageResponse=PageResponse.of(page,NursingGradeVo.class);
        return nursingGradeVoPageResponse;

    }

    @Override
    public NursingGradeVo queryById(Long id) {
        NursingGrade nursingGrade = nursingGradeMapper.queryById(id);
        NursingGradeVo nursingGradeVo = BeanUtil.toBean(nursingGrade, NursingGradeVo.class);
        return nursingGradeVo;
    }

    @Override
    public void update(NursingGradeDto nursingGradeDto) {
        NursingGrade nursingGrade = BeanUtil.toBean(nursingGradeDto, NursingGrade.class);
        nursingGradeMapper.update(nursingGrade);
    }

    @Override
    public void delete(Long id) {
        nursingGradeMapper.delete(id);
    }

    @Override
    public void updateProjectStatus(Long id, Integer status) {
        nursingGradeMapper. updateProjectStatus(id,status);
    }
}
